<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      body {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
      }
      .text {
        --mainColor: rgba(21, 144, 222);
        --secondary: #bbb;
        position: relative;
      }
      .text > input {
        border: 0;
        outline: 0;
        border: 0.1rem solid var(--secondary);
        padding: 0.5rem;
      }
      .text > label {
        position: absolute;
        top: 50%;
        left: 0.3rem;
        transform: translateY(-50%);
        color: var(--secondary);
        transition: 0.2s;
        background-color: #fff;
      }
      .text > input:focus,
      .text > input:not(:placeholder-shown) {
        border: 0.1rem solid var(--mainColor);
      }
      .text > input:focus + label,
      .text > input:not(:placeholder-shown) + label {
        color: var(--mainColor);
        top: 0;
        font-size: 0.8rem;
      }
    </style>
  </head>
  <body>
    <div class="wrap">
      <div class="text">
        <input type="text" id="username" placeholder="" />
        <label for="username">昵称</label>
      </div>
    </div>
  </body>
</html>
